﻿@inject IDataCacheService _dataCacheService

<MDCard Class="mb-4 pa-4 pb-0 discount-screen-card">
    <div class="mb-4 title-card">
        <div style="display: flex;flex-direction: column;align-items: center;width: 100%;">
            @if (_dataCacheService.IsApp == false)
            {
                <h1>折扣中的游戏</h1>
            }
            <div style="word-break: break-all; text-align-last: center;" class="label-large">
                已筛选 @_dataCacheService.DiscountPageCatcheHelper.Items.Count() 个游戏
                @if (_dataCacheService.IsApp)
                {
                    <br />
                }
                else
                {
                    <span>，</span>
                }
                Steam信息来源：<a href="https://isthereanydeal.com/" rel="noreferrer"> https://isthereanydeal.com/</a>
            </div>
        </div>
        <div style=" display: flex; align-items: flex-end; ">
            <CnGalWebSite.Components.Buttons.MasaButton Fab Tooltip="@(_dataCacheService.DiscountPageCatcheHelper.ShowAdvancedOptions?"折叠高级选项":"展开高级选项")" Icon="@IconType.Filter.ToIconString()" OnClick="OnSwitch" />
         </div>
     </div>
     @if (_dataCacheService.DiscountPageCatcheHelper.ShowAdvancedOptions)
    {
            <div style="" class="w-100 input-card">
                <div style="max-width: 120px; width: 100%;">
                    <CnGalWebSite.Components.Inputs.MasaSelecte Value="_dataCacheService.DiscountPageCatcheHelper.ScreenType" ValueChanged="OnScreenTypeChanged" TValue="ScreenSteamType" Class="pt-0" Label="折扣" />
                </div>
                <div style="max-width: 140px; width: 100%;">
                    <CnGalWebSite.Components.Inputs.MasaSelecte Value="_dataCacheService.DiscountPageCatcheHelper.OrderType" ValueChanged="OnOrderTypeChanged" TValue="SteamSortType" Class="pt-0" Label="排序" />
                </div>

                @if (_dataCacheService.DiscountPageCatcheHelper.ShowAdvancedOptions || _dataCacheService.IsApp == false)
                {
                    <div style="max-width: 270px; width: 100%;">
                        <CnGalWebSite.Components.Inputs.MasaSelecte Value="_dataCacheService.DiscountPageCatcheHelper.PurchasedType" ValueChanged="OnPurchasedTypeChanged" TValue="PurchasedSteamType" Class="pt-0" Label="库存（请先前往个人空间绑定Steam账号）" />
                    </div>
                }
                <div style="max-width: 120px; width: 100%;">
                    <CnGalWebSite.Components.Inputs.MasaSelecte Value="_dataCacheService.DiscountPageCatcheHelper.SteamDisplayType" ValueChanged="OnDisplayTypeChanged" TValue="SteamDisplayType" Class="pt-0" Label="样式" />
                </div>
                <div>
                    <MCheckbox Class="mt-0" Value="_dataCacheService.DiscountPageCatcheHelper.ShowNoDiscountGames" TValue="bool" ValueChanged="ShowNoDiscountGamesChanged" Label="显示无折扣的游戏" />
                </div>
                <div style="max-width: 400px; width: 100%;">
                    <MSlider Max="DiscountPageHelper.MaxOriginalPriceLimit" Min="5" Step="5" Value="_dataCacheService.DiscountPageCatcheHelper.MaxOriginalPrice" TValue="double" ValueChanged="MaxOriginalPriceChanged"
                             Label="@(_dataCacheService.DiscountPageCatcheHelper.MaxOriginalPrice>=DiscountPageHelper.MaxOriginalPriceLimit?"任意价格":_dataCacheService.DiscountPageCatcheHelper.MaxOriginalPrice<10?"免费发布的游戏":$"原价低于 {_dataCacheService.DiscountPageCatcheHelper.MaxOriginalPrice:00} ￥")" />
                </div>

            </div>
    }
</MDCard>

@code {
    [Parameter]
    public EventCallback<PurchasedSteamType> ValueChanged { get; set; }


    public void OnSwitch()
    {
        _dataCacheService.DiscountPageCatcheHelper.ShowAdvancedOptions = !_dataCacheService.DiscountPageCatcheHelper.ShowAdvancedOptions;
        StateHasChanged();
    }

    public async Task OnScreenTypeChanged(ScreenSteamType type)
    {
        _dataCacheService.DiscountPageCatcheHelper.ScreenType = type;
        _dataCacheService.DiscountPageCatcheHelper.CurrentPage = 1;
        await ValueChanged.InvokeAsync();
    }
    public async Task OnOrderTypeChanged(SteamSortType type)
    {
        _dataCacheService.DiscountPageCatcheHelper.OrderType = type;
        await ValueChanged.InvokeAsync();
    }

    public async Task OnDisplayTypeChanged(SteamDisplayType type)
    {
        _dataCacheService.DiscountPageCatcheHelper.SteamDisplayType = type;
        await ValueChanged.InvokeAsync();
    }

    public async Task OnPurchasedTypeChanged(PurchasedSteamType type)
    {
        _dataCacheService.DiscountPageCatcheHelper.PurchasedType = type;
        _dataCacheService.DiscountPageCatcheHelper.CurrentPage = 1;
        await ValueChanged.InvokeAsync();
    }

    public async Task ShowNoDiscountGamesChanged(bool show)
    {
        _dataCacheService.DiscountPageCatcheHelper.ShowNoDiscountGames = show;
        _dataCacheService.DiscountPageCatcheHelper.CurrentPage = 1;
        await ValueChanged.InvokeAsync();
    }
    public async Task MaxOriginalPriceChanged(double price)
    {
        _dataCacheService.DiscountPageCatcheHelper.MaxOriginalPrice = price;
        await ValueChanged.InvokeAsync();
    }
}
